home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
fitobj.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
144 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* fitobj -
* Fit a sgi object into a unit cube.
*
* Paul Haeberli - 1990
*/
#include "stdio.h"
#include "math.h"
#include "vect.h"
#include "sgiobj.h"
main(argc,argv)
int argc;
char **argv;
{
sgiobj *obj;
if(argc<3) {
fprintf(stderr,"fitobj: in.bin out.bin\n");
exit(1);
}
obj = readsgiobj(argv[1]);
fitobj(obj,-0.5,0.5,-0.5,0.5,-0.5,0.5);
writesgiobj(argv[2],obj);
exit(0);
}
float oxmin, oxmax;
float oymin, oymax;
float ozmin, ozmax;
float xavg, yavg, zavg;
float xmid, ymid, zmid;
float sc;
findmax(fptr)
float *fptr;
{
fptr += OFFSET_POINT;
if(*fptr<oxmin)
oxmin = *fptr;
if(*fptr>oxmax)
oxmax = *fptr;
fptr++;
if(*fptr<oymin)
oymin = *fptr;
if(*fptr>oymax)
oymax = *fptr;
fptr++;
if(*fptr<ozmin)
ozmin = *fptr;
if(*fptr>ozmax)
ozmax = *fptr;
}
scalepnt(fptr)
float *fptr;
{
fptr += OFFSET_POINT;
*fptr = xavg+(sc*(*fptr-xmid));
fptr++;
*fptr = yavg+(sc*(*fptr-ymid));
fptr++;
*fptr = zavg+(sc*(*fptr-zmid));
}
fitobj(obj,xmin,xmax,ymin,ymax,zmin,zmax)
sgiobj *obj;
float xmin,xmax,ymin,ymax,zmin,zmax;
{
float delx, dely, delz;
float odelx, odely, odelz;
float tdelx, tdely, tdelz;
float *fptr;
int npoints, mode;
delx = xmax-xmin;
dely = ymax-ymin;
delz = zmax-zmin;
oxmin = oymin = ozmin = 1000.0;
oxmax = oymax = ozmax = -1000.0;
applytoverts(obj,findmax);
tdelx = odelx = oxmax-oxmin;
tdely = odely = oymax-oymin;
tdelz = odelz = ozmax-ozmin;
tdelx /= delx;
tdely /= dely;
tdelz /= delz;
if(tdelx>tdely) {
if(tdelx>tdelz) {
mode = 1;
} else {
mode = 3;
}
} else {
if(tdely>tdelz) {
mode = 2;
} else {
mode = 3;
}
}
switch(mode) {
case 1:
sc = delx/odelx;
break;
case 2:
sc = dely/odely;
break;
case 3:
sc = delz/odelz;
break;
}
npoints = obj->nlongs/PNTLONGS;
fptr = (float *)obj->data;
fptr+= OFFSET_POINT;
xmid = (oxmin+oxmax)/2.0;
ymid = (oymin+oymax)/2.0;
zmid = (ozmin+ozmax)/2.0;
xavg = (xmin+xmax)/2.0;
yavg = (ymin+ymax)/2.0;
zavg = (zmin+zmax)/2.0;
applytoverts(obj,scalepnt);
}